package backOffice;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddServlet
 */
public class AddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private JDBCCourseDAO jdbccourse;
  
    public AddServlet() {
        super(); 
        jdbccourse = new JDBCCourseDAO();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
	
		String code = request.getParameter("code");
		String title = request.getParameter("title");
		String dbegin = request.getParameter("dbegin");
		String dend = request.getParameter("dend");
		String loc = request.getParameter("loc");
		try{
			jdbccourse.addCourse(code, title, dbegin, dend, loc);
			request.getRequestDispatcher("SearchList.jsp").forward(request,
					response);
		}		
		catch(Exception e){
			request.getRequestDispatcher("error.jsp").forward(request,
					response);			
		}			
	}

}
